package com.nd.android.u.ui.longClickMenu.messageList;

import ims.utils.CommUtil;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.nd.android.u.allCommonUtils.ToastUtils;
import com.nd.android.u.controller.ChatConst;
import com.nd.android.u.controller.ChatConst.LocalMessageType;
import com.nd.android.u.controller.ChatConst.MessageContentType;
import com.nd.android.u.controller.ChatGlobalVariable;
import com.nd.android.u.controller.MessageConst.MessageState;
import com.nd.android.u.controller.innerInterface.IChatListLongClickMenu;
import com.nd.android.u.controller.innerInterface.IMessageDisplay;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.activity.recent_contact.RecentContactRecordActivity;
import com.product.android.business.ApplicationVariable;

/**
 * [转发] 菜单项
 * @author yufeng
 * @version 创建时间：2014-7-18 上午10:40:44
 */
public class MenuItemForward implements IChatListLongClickMenu {

    
    private IMessageDisplay mMessage;
    
    @Override
    public String getLabel() {
        return ApplicationVariable.INSTANCE.applicationContext
                .getString(R.string.context_menu_item_forward);
    }

    @Override
    public void onClick(Context context) {
        ChatGlobalVariable.getInstance().setIstransmit(true);

        if (!CommUtil.JudgeNetWorkStatus(context)) {
            ToastUtils.display(context, R.string.net_warn_no_network);
            return;
        }

        Intent intent = new Intent(context, RecentContactRecordActivity.class);
        intent.putExtra(ChatConst.KEY.REPOST_DATA, mMessage.getGenerateId());

        if (mMessage.getMessageType() == LocalMessageType.PERSON) {
            Object obj = mMessage.getTypeId();
            if (obj instanceof Long) {
                intent.putExtra(ChatConst.KEY.REPOST_FID, (Long) mMessage.getTypeId());
            } else {
                Log.w("@@", "getFriend() not Long");
            }
        } else {
            intent.putExtra(ChatConst.KEY.REPOST_GID, mMessage.getTypeId().toString());
        }

        intent.putExtra(ChatConst.KEY.REPOST_TYPE, mMessage.getMessageContentType());
        context.startActivity(intent);
    }

    @Override
    public boolean isEnable(IMessageDisplay message) {
    	mMessage=message;
        // 系统消息和应用消息没有弹出菜单, 公众号消息只有"删除"项
        int messageType=mMessage.getMessageType();
        int messageContentType=mMessage.getMessageContentType();
        
        if (messageType == LocalMessageType.SYSTEM ||messageType == LocalMessageType.APP
                || messageType == LocalMessageType.PUBLIC_NUMBER) {
            return false;
        }
        int extraFlag=mMessage.getExtraFlag();
        if (messageType==LocalMessageType.GROUP && (messageContentType == MessageContentType.FILE 
                || messageContentType == MessageContentType.OLD_FILE)){
            return false;
        }
        if (extraFlag == MessageState.UPLOAD_FAIL
                || extraFlag == MessageState.SEND_FAIL
                || extraFlag == MessageState.SENDING){
            return false;
        }
        return true;
    }

}
